﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SignIn.aspx.cs" Inherits="SignIn" %>

<%@ Register TagPrefix="flow" TagName="Footer" Src="Footer.ascx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="<%=Lang %>">
<head id="Head1" runat="server">
    <meta charset="utf-8" />
    <base href="/" target="_top" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <title></title>
    <!--JQuery was release on The MIT License-->
    <script src="/Script/jquery-2.0.0.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="https://flow.jackjcsn.com/Styles/basic.css" />
    <link rel="stylesheet" type="text/css" href="https://flow.jackjcsn.com/Styles/form.css" />
    <style type="text/css">
        #howto
        {
            width: 216px;
        }
    </style>
</head>
<body>
    <h1><%=Title%></h1>
    <asp:Literal runat="server" ID="EnableScript" Text="<%$ Resources:R,EnableScript %>" />
    <div id="main">
        <form action="#" method="post" id="signin" name="signin" autocomplete="off">
            <h3>登录</h3>
            <input type="password" id="sign_password" placeholder="在此输入您的通行证号" name="sign_password" />
            <input type="submit" id="signin_submit" name="signin_submit" value="登录" />
        </form>
        <form action="#" method="post" id="signup" name="signup" autocomplete="off">
            <h3>免费注册</h3>
            <input type="text" id="signup_username" name="signup_username" value="" placeholder="在此输入你的昵称" />
            <input type="checkbox" id="signup_agree" name="signup_agree" />
            <label for="signup_agree"><span class="box"></span>我已阅读并知晓FlowWorld的相关隐私条款和用户策略</label>
            <input type="submit" id="signup_submit" disabled="disabled" name="signup_submit" value="注册" />
        </form>
        <form id="nav" runat="server">
            <ul style="list-style-type: none">
                <li><asp:Button ID="Button1" runat="server" Text="使用游客身份登录到游戏" OnClick="Button1_Click" /></li>
                <%--<li><input type="submit" id="howto"  value="怎么玩？" /></li>--%>
            </ul>
        </form>
        <flow:Footer runat="server" />
    </div>
    <script type="text/javascript">
        $(document).ready(function (evt)
        {
            $("#signin").submit(function (evt)
            {
                var epass = $("#sign_password").val();
                $.ajax({
                    type: "POST",
                    url: "/Ajax/SignIn/SignIn/",
                    data: "epass=" + epass,
                    success: SignCallback
                });
                $("#signin input[type=submit]").attr("disabled", "disabled");
                evt.preventDefault();
                evt.stopImmediatePropagation();
                evt.stopPropagation();
            });

            $("#signup_agree").change(function (evt)
            {
                if ($("#signup_agree")[0].checked)
                {
                    $("#signup input[type=submit]").removeAttr("disabled");
                }
                else
                {
                    $("#signup input[type=submit]").attr("disabled", "disabled");
                }
            });

            $("#signup").submit(function (evt)
            {
                var user = $("#signup_username").val();
                $.ajax({
                    type: "POST",
                    url: "/Ajax/SignIn/SignUp/",
                    data: "user=" + user,
                    success: SignUpCallback
                });
                $("#signup input").attr("disabled", "disabled");
                evt.preventDefault();
                evt.stopImmediatePropagation();
                evt.stopPropagation();
            });
        });

        function SignCallback(evt)
        {
            var res = JSON.parse(evt);
            if (res.bOk)
            {
                MsgBox(res.sMsg);
                if (res.sActions)
                {
                    window.location.href = res.sActions;
                }
            }
            else
            {
                if (res.sDebug)
                {
                    console.error(res.sDebug);
                }
                if (res.data)
                {
                    console.info(res.data);
                }
                MsgBox(res.sMsg);
                if (res.sActions)
                {
                    window.location.href = res.sActions;
                }
            }
            $("#signin input[type=submit]").removeAttr("disabled");
        }

        function SignUpCallback(evt)
        {
            var res = JSON.parse(evt);
            if (res.bOk)
            {
                MsgBox(res.sMsg);
                MsgBox("您的通行证号为:\n" + res.data.EPASS + "\n请牢记该号码，您之后需要使用此号码登录游戏");
                if (res.sActions)
                {
                    window.location.href = res.sActions;
                }
            }
            else
            {
                if (res.sDebug)
                {
                    console.error(res.sDebug);
                }
                if (res.data)
                {
                    console.info(res.data);
                }
                MsgBox(res.sMsg);
                if (res.sActions)
                {
                    window.location.href = res.sActions;
                }
            }
            $("#signup input").removeAttr("disabled");
        }

        function MsgBox(str)
        {
            alert(str);
        }
    </script>
</body>
</html>
